//
//  WPHeaderView.m
//  wobingwoyi
//
//  Created by WGP on 16/7/27.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPHeaderView.h"

@interface WPHeaderView ()

@property(nonatomic,strong)UIImageView *bgImageView;
@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,strong)UIButton *settingBtn;

@property(nonatomic,copy)void(^handleBlock)(WPMineHeaderViewBtnType btnType);

@end

@implementation WPHeaderView

+(instancetype)headerViewWithHandleBlock:(void(^)(WPMineHeaderViewBtnType btnType))handleBlock
{
    return [[self alloc] initWithheaderViewHandleBlock:handleBlock];
}

-(instancetype)initWithheaderViewHandleBlock:(void(^)(WPMineHeaderViewBtnType btnType))handleBlock
{
    if (self = [super init]) {
        
        self.handleBlock = handleBlock;
        [self setupUI];
    }
    return self;
}



-(void)setupUI
{
    
    self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgImage"]];
    [self addSubview:self.bgImageView];
    
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.text = @"我的";
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = [UIFont systemFontOfSize:18];
    self.titleLabel.textColor = [UIColor whiteColor];
    [self.titleLabel sizeToFit];
    [self addSubview:self.titleLabel];
   
    
    self.settingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.settingBtn setImage:[UIImage imageNamed:@"shezhi"] forState:UIControlStateNormal];
    [self.settingBtn addTarget:self action:@selector(settingBtnDidClick) forControlEvents:UIControlEventTouchDown];
    [self.settingBtn sizeToFit];
    [self addSubview:self.settingBtn];
    
    self.iconBtn = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-touxiang"]];
    self.iconBtn.userInteractionEnabled = YES;
    
    CGFloat iconBtnWidth = 80 * KWIDTH_SCALE;
    self.iconBtn.layer.cornerRadius = iconBtnWidth*0.5;
    self.iconBtn.layer.masksToBounds = YES;
    self.iconBtn.layer.borderWidth = 1;
    self.iconBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    
    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(loginBtnDidClick)];
    [self.iconBtn addGestureRecognizer:tapGR];
    [self addSubview:self.iconBtn];
    
    self.nickName = [[UILabel alloc] init];
    self.nickName.text = @"你好,请先登录";
    self.nickName.font = [UIFont systemFontOfSize:14];
    self.nickName.textColor = [UIColor whiteColor];
    [self.nickName sizeToFit];
    [self addSubview:self.nickName];
    
    [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self);

    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self).offset(33*KWIDTH_SCALE);
    }];
    
    [self.settingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.titleLabel);
        make.right.equalTo(self).offset(-10);
    }];
    
    [self.iconBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(iconBtnWidth);
        make.centerX.equalTo(self);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(23*KWIDTH_SCALE);
    }];
    
    [self.nickName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.iconBtn.mas_bottom).offset(13*KWIDTH_SCALE);
    }];

}

-(void)settingBtnDidClick
{
    if (self.handleBlock) {
        self.handleBlock(WPMineHeaderViewBtnTypeSetting);
    }
}

-(void)loginBtnDidClick
{
    if (self.handleBlock) {
        self.handleBlock(WPMineHeaderViewBtnTypeLogin);
    }
}

@end





